﻿using System;
using System.Collections.Generic;
using System.Text;
using Watchdog.Bll.Base;
using Watchdog.Bll.Factory;

namespace Watchdog.Bll {

    public partial class Definition : DefinitionBase {

        internal Definition () : base () {}

        internal Definition ( Watchdog.Facade.Definition definition ) : base (definition) { }
		
		#region [ Parent objects ]


		#endregion

		#region [ Many to many relations ]

		List<TargetType> targettypes;
		public List<TargetType> TargetTypes {
			get {
				if ( targettypes == null )
					targettypes = TargetTypeFactory.GetByDefinition(this.Id);
				return targettypes;
			}
		}

		#endregion

		#region [ Add & Remove methods for many to many relations ]

		public void AddTargetType (TargetType targettype) {
			DefinitionFactory.AddTargetType (this, targettype);
			//reset the collection;
			targettypes = null;
		}

		public void RemoveTargetType (TargetType targettype) {
			DefinitionFactory.RemoveTargetType (this, targettype);
			//reset the collection;
			targettypes = null;
		}

		#endregion
		
		#region [ One to many relations ]

		List<AssemblyFile> assemblyfiles;
		public List<AssemblyFile> AssemblyFiles {
			get {
				if ( assemblyfiles == null )
					assemblyfiles = AssemblyFileFactory.GetByDefinition(this.Id);
				return assemblyfiles;
			}
		}

		List<Config> configs;
		public List<Config> Configs {
			get {
				if ( configs == null )
					configs = ConfigFactory.GetByDefinition(this.Id);
				return configs;
			}
		}

		List<Test> tests;
		public List<Test> Tests {
			get {
				if ( tests == null )
					tests = TestFactory.GetByDefinition(this.Id);
				return tests;
			}
		}

		#endregion
		
		#region [ Add & Remove methods for one to many relations ]

		public void AddAssemblyFile (AssemblyFile assemblyfile) {
			assemblyfile.Definition = this;
			assemblyfile.Update();
			//DefinitionFactory.AddAssemblyFile (this, assemblyfile);
			//reset the collection;
			assemblyfiles = null;
		}

		public void RemoveAssemblyFile (AssemblyFile assemblyfile) {
			assemblyfile.Definition = this;
			assemblyfile.Delete();
			//DefinitionFactory.RemoveAssemblyFile (this, assemblyfile);
			//reset the collection;
			assemblyfiles = null;
		}

		public void AddConfig (Config config) {
			config.Definition = this;
			config.Update();
			//DefinitionFactory.AddConfig (this, config);
			//reset the collection;
			configs = null;
		}

		public void RemoveConfig (Config config) {
			config.Definition = this;
			config.Delete();
			//DefinitionFactory.RemoveConfig (this, config);
			//reset the collection;
			configs = null;
		}

		public void AddTest (Test test) {
			test.Definition = this;
			test.Update();
			//DefinitionFactory.AddTest (this, test);
			//reset the collection;
			tests = null;
		}

		public void RemoveTest (Test test) {
			test.Definition = this;
			test.Delete();
			//DefinitionFactory.RemoveTest (this, test);
			//reset the collection;
			tests = null;
		}

		#endregion

    }
}
